#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re
from typing import List, Dict
from .base import FilterRule

class CodeBlockLanguageTagFilter(FilterRule):
    """代码块语言标记修改过滤规则"""
    
    def should_filter(self, add_content: str, remove_content: str, hunk_changes: List[Dict]) -> bool:
        """判断是否为代码块语言标记修改"""
        add_clean = add_content.strip()
        remove_clean = remove_content.strip()
        
        # 支持 ``` → ```lang 或 ```langA → ```langB 的变化
        pattern = r'^```[A-Za-z0-9._+-]*$'
        add_match = re.match(pattern, add_clean)
        remove_match = re.match(pattern, remove_clean)
        
        if not (add_match and remove_match):
            return False
        
        # 两者都以三反引号开头且只有语言标记不同
        return add_clean.startswith('```') and remove_clean.startswith('```') and add_clean != remove_clean
    
    def get_filter_reason(self) -> str:
        return "code_block_language_tag_change"


